package com.burger.burgerpicturebackend.service.impl;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.burger.burgerpicturebackend.model.dto.category.CategoriesQueryRequest;
import com.burger.burgerpicturebackend.model.entity.Categories;
import com.burger.burgerpicturebackend.service.CategoriesService;
import com.burger.burgerpicturebackend.mapper.CategoriesMapper;
import org.springframework.stereotype.Service;

/**
* @author zjb13
* @description 针对表【categories】的数据库操作Service实现
* @createDate 2025-01-21 00:17:41
*/
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories>
    implements CategoriesService{

    @Override
    public QueryWrapper<Categories> getQueryWrapper(CategoriesQueryRequest categorysQueryRequest) {
        QueryWrapper<Categories> queryWrapper = new QueryWrapper<>();
        if (categorysQueryRequest == null) {
            return queryWrapper;
        }
        Long categoryId = categorysQueryRequest.getCategoryId();
        String categoryName = categorysQueryRequest.getCategoryName();
        String sortField = categorysQueryRequest.getSortField();
        String sortOrder = categorysQueryRequest.getSortOrder();
        // 拼接查询条件
        queryWrapper.eq(ObjUtil.isNotEmpty(categoryId), "categoryId", categoryId);
        queryWrapper.like(StrUtil.isNotBlank(categoryName), "categoryName", categoryName);
        // 排序
        queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
        return queryWrapper;
    }
}




